﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace ChinaCustoms.Qingdao.Workflow.Activities.Chooser
{
    public class ChooserForGeneralUser : UITypeEditor
    {
        /// <summary>
        /// 使用模式窗口作为 窗口的显示方式
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        /// <summary>
        /// 获取UI上,选择的信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edSvc != null)
            {
                // Display an selection control and retrieve the value.
                UserForm userForm = new UserForm();
                userForm.UserNames = (string)value;
                if (edSvc.ShowDialog(userForm) == System.Windows.Forms.DialogResult.OK)
                {
                    return userForm.UserNames;
                }
            }
            return value;
        }


        /// <summary>
        /// 是否在属性面板中生成一个小缩略图
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context)
        {
            return false;
        }
    }
}
